Add test for unknown named parameters on native variadic functions#5433
Closed
Amoifr wants to merge 1 commit intophpstan:2.0.xfrom
Closed
Add test for unknown named parameters on native variadic functions#5433Amoifr wants to merge 1 commit intophpstan:2.0.xfrom
Amoifr wants to merge 1 commit intophpstan:2.0.xfrom
Conversation
Adds a regression test for #14408 verifying that unknown named arguments passed to native variadic functions like sprintf() are properly detected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a regression test for phpstan/phpstan#14408.
The test verifies that unknown named arguments passed to native variadic functions like
sprintf()are properly reported as errors, since PHP rejects them at runtime (ArgumentCountError: sprintf() does not accept unknown named parameters).Based on code analysis, it appears the detection logic at
FunctionCallParametersCheck:707already handles this case (!$isNativelyVariadic || $isBuiltin), combined with the fact thatPhp8SignatureMapProviderstrips the variadic parameter fromnamedArgumentsVariants. If the test passes on CI, this confirms the issue is already resolved in 2.0.x. If it fails, it pinpoints where the fix is needed.Test cases:
sprintf(format: '%s', foo: 'bar')— should reportUnknown parameter $foosprintf(format: '%s %s', values: 'hello')— should pass (known parameter)call_user_func('strtolower', str: 'HELLO')— should pass (forwards args to callback)